package com.xiedafeng.www.view;

import com.xiedafeng.www.controller.EventController;
import com.xiedafeng.www.po.Circle;
import com.xiedafeng.www.po.Event;
import com.xiedafeng.www.po.User;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class CreateEventView {
    TextField content=new TextField();
    Stage stage=new Stage();
    public void create(User user, Circle circle){
        Text tip=new Text("请输入瓜的内容");
        GridPane gridPane=new GridPane();
        gridPane.add(tip,0,0);
        gridPane.add(content,0,1,1,4);
        Button confirm=new Button("确定");
        confirm.setOnMouseClicked(event -> {
            try {
                confirmButton(user,circle);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        gridPane.add(confirm,0,5);
        Scene scene=new Scene(gridPane);
        stage.setScene(scene);
        stage.showAndWait();
    }
    private void confirmButton(User user, Circle circle) throws Exception {
        Event event=new Event();
        event.setPublisher(user.getName());
        event.setContent(content.getText());
        EventController eventController=new EventController();
        eventController.createEvent(user,circle,event);
    }
}
